
package com.jf.cloud.distribution.controller.platform;

import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.PhoneUtil;
import cn.hutool.core.util.StrUtil;
import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.common.util.PrincipalUtil;
import com.jf.cloud.distribution.dto.DistributionUserBanDTO;
import com.jf.cloud.distribution.service.DistributionUserBanService;
import com.jf.cloud.distribution.vo.DistributionUserBanVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 分销封禁记录
 *
 * @author zz
 * @date 2021-08-09 14:14:08
 */
@RestController("platformDistributionUserBanController")
@RequestMapping("/p/distribution_user_ban")
@Tag(name = "platform-分销封禁记录")
public class DistributionUserBanController {

    @Autowired
    private DistributionUserBanService distributionUserBanService;

    @Value("${jfcloud.expose.operation.auth:}")
    private Boolean permission;

    @GetMapping("/page")
    @Operation(summary = "获取分销封禁记录列表" , description = "分页获取分销封禁记录列表")
    public ServerResponseEntity<PageVO<DistributionUserBanVO>> page(@Valid PageDTO pageDTO,@ParameterObject DistributionUserBanDTO distributionUserBanDTO) {
        PageVO<DistributionUserBanVO> page = distributionUserBanService.page(pageDTO, distributionUserBanDTO);
        if (BooleanUtil.isFalse(permission)) {
            for (DistributionUserBanVO distributionUserBanVO : page.getList()) {
                if (StrUtil.isNotBlank(distributionUserBanVO.getNickName()) && PrincipalUtil.isMobile(distributionUserBanVO.getNickName())) {
                    distributionUserBanVO.setNickName(PhoneUtil.hideBetween(distributionUserBanVO.getNickName()).toString());
                }
                if (StrUtil.isNotBlank(distributionUserBanVO.getUserMobile())) {
                    distributionUserBanVO.setUserMobile(PhoneUtil.hideBetween(distributionUserBanVO.getUserMobile()).toString());
                }
            }
        }
        return ServerResponseEntity.success(page);
    }
}
